package com.share.spock

import com.share.dgs.fetcher.HelloDataFetcher
import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
import org.springframework.test.web.servlet.result.MockMvcResultMatchers
import spock.lang.Specification

/**
 * @author caifan* @created 2021/6/4
 * @description: spock teste
 */
@WebMvcTest
class HelloFetcherTest extends Specification {

    @Autowired
    MockMvc mockMvc;

    @SpringBean
    private HelloDataFetcher helloDataFetcher= Stub();

    def "graphql test"() {

        given: "fetcher test"

        expect:
        mockMvc.perform(MockMvcRequestBuilders.get("http://localhost:8089/graphql")
                .queryParam("{hello(name: \"张三\")} {}"))
                .andExpect(MockMvcResultMatchers.status().isOk())
//                .andExpect(MockMvcResultMatchers.content().print())
//                .andExpect(content().string("{\"data\": {\n" +
//                "        \"hello\": \"hello:张三!\"\n" +
//                "    }}"));

    }
}
